package com.watchthelan.repository;

import java.util.List;

import com.watchthelan.domain.Administrator;

public class InMemoryAdministratorDao implements AdministratorDao {
	
	private List<Administrator> administratorList;
	
	public InMemoryAdministratorDao(List<Administrator> administrators) {
		this.administratorList = administrators;
	}

	@Override
	public void addAdministrator(Administrator administrator) {
		this.administratorList.add(administrator);
	}

	@Override
	public void deleteAdministratorById(Long id) {
		for (Administrator administrator: this.administratorList) {
			if (administrator.getId() == id) {
				this.administratorList.remove(administrator);
				return;
			}
		}

	}

	@Override
	public Administrator getAdministratorById(Long id) {
		for (Administrator administrator: this.administratorList) {
			if (administrator.getId() == id) {
				return administrator;
			}
		}
		return null;
	}

	@Override
	public List<Administrator> getAdministrators() {
		return this.administratorList;
	}

	@Override
	public void updateAdministrator(Administrator administrator) {
		for (Administrator admin: this.administratorList) {
			if (admin.getId() == administrator.getId()) {
				admin.setName(administrator.getName());
				admin.setUsername(administrator.getUsername());
				admin.setPassword(administrator.getPassword());
				return;
			}
		}
	}

	@Override
	public Administrator getAdministratorByUsername(String username) {
		for (Administrator a: administratorList) {
			if (a.getUsername().equals(username)) {
				return a;
			}
		}
		return null;
	}

}
